<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="报表代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bbdm">
              <a-input v-model="model.bbdm" placeholder="请输入报表代码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zwmc">
              <a-input v-model="model.zwmc" placeholder="请输入中文名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物理表名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wlbm">
              <a-input v-model="model.wlbm" placeholder="请输入物理表名"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报表分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bbfl">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择报表分类"
                v-model="model.bbfl"
                dict="rspc_param_config,name,code"
                pidValue="8f6d66d32c3649cb9a788c24fb3a8260"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="格式类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gslb">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择格式类别"
                v-model="model.gslb"
                dict="rspc_param_config,name,code"
                pidValue="431a1922b7484e0abd5e3886dd3c9232"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报送频度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bspd">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择报送频度"
                v-model="model.bspd"
                dict="rspc_param_config,name,code"
                pidValue="348523d249be49c68275466beacdcd52"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="精度位数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jdws">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择精度位数"
                v-model="model.jdws"
                dict="rspc_param_config,name,code"
                pidValue="3079103a80fb4f9982631e6f1228d97d"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="汇总类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hzlx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择汇总类型"
                v-model="model.hzlx"
                dict="rspc_param_config,name,code"
                pidValue="0b87acaa9d8a4ecba21e6afd02f5e122"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="币种单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zbdw">
              <j-tree-select
                showSearch
                ref="treeSelect"
                placeholder="请选择币种单位"
                v-model="model.zbdw"
                dict="rspc_param_config,name,code"
                pidValue="2B290F72BF7E4B39B2D56F1934D5F43F"
                hasChildField="has_child"
              >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="生效日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startrq">
              <j-date placeholder="请选择生效日期" v-model="model.startrq" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="失效日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endrq">
              <j-date placeholder="请选择失效日期" v-model="model.endrq" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'RspcReportMetaForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        bbdm: [{ required: true, message: '请输入报表代码!' }],
        zwmc: [{ required: true, message: '请输入中文名称!' }],
        wlbm: [{ required: true, message: '请输入物理表名!' }],
        bbfl: [{ required: true, message: '请选择报表分类!' }],
        gslb: [{ required: true, message: '请选择格式类别!' }],
        bspd: [{ required: true, message: '请选择报送频度!' }],
        jdws: [{ required: true, message: '请选择精度位数!' }],
        hzlx: [{ required: true, message: '请选择汇总类型!' }],
        zbdw: [{ required: true, message: '请选择币种单位!' }],
      },
      url: {
        add: '/rspc/rspcReportMeta/add',
        edit: '/rspc/rspcReportMeta/edit',
        queryById: '/rspc/rspcReportMeta/queryById',
      },
    }
  },
  //   computed: {
  //     formDisabled(){
  //       return this.disabled
  //     },
  //     wrapperCol: {
  //       xs: { span: 24 },
  //       sm: { span: 16 },
  //     },
  //     confirmLoading: false,
  //     validatorRules: {
  //       bbdm: [{ required: true, message: '请输入报表代码!' }],
  //       zwmc: [{ required: true, message: '请输入中文名称!' }],
  //       wlbm: [{ required: true, message: '请输入物理表名!' }],
  //       bbfl: [{ required: true, message: '请输入报表分类!' }],
  //       gslb: [{ required: true, message: '请输入格式类别!' }],
  //       bspd: [{ required: true, message: '请输入报送频度!' }],
  //       jdws: [{ required: true, message: '请输入精度位数!' }],
  //       hzlx: [{ required: true, message: '请输入汇总类型!' }],
  //       zbdw: [{ required: true, message: '请输入币种单位!' }],
  //       startrq: [{ required: true, message: '请选择生效日期!' }],
  //       endrq: [{ required: true, message: '请选择失效日期!' }],
  //     },
  //     submitForm () {
  //       const that = this;
  //       // 触发表单验证
  //       this.$refs.form.validate(valid => {
  //         if (valid) {
  //           that.confirmLoading = true;
  //           let httpurl = '';
  //           let method = '';
  //           if(!this.model.id){
  //             httpurl+=this.url.add;
  //             method = 'post';
  //           }else{
  //             httpurl+=this.url.edit;
  //              method = 'put';
  //           }
  //           httpAction(httpurl,this.model,method).then((res)=>{
  //             if(res.success){
  //               that.$message.success(res.message);
  //               that.$emit('ok');
  //             }else{
  //               that.$message.warning(res.message);
  //             }
  //           }).finally(() => {
  //             that.confirmLoading = false;
  //           })
  //         }

  //       })
  //     },
  //   }
  // },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
  },
}
</script>